home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / evaltrac.lha / tex / evaltrace11.sty < prev    next >
Text File  |  1989-11-29  |  4KB  |  105 lines

  1. % Latex style for evaltrace diagrams in 11pt documents.
  2. % Copyright, Peter Lee and David Touretzky, 1989
  3. %
  4. % See "Visualizing evaluation in applicative languages",
  5. %  by David S. Touretzky and Peter Lee
  6. %
  7. % This style is loosely based on Jon Rees' code.sty, which was
  8. % originally based on macros found in Chuck Rich's library.
  9.  
  10. \makeatletter
  11.  
  12. \font\et et10
  13. \font\cmtt cmtt10
  14.  
  15. % \etobeyspaces turns all spaces into non-breakable spaces.
  16. % Note: this is like \@vobeyspaces except without spurious space in defn.
  17. {\catcode`\ =\active\gdef\etobeyspaces{\catcode`\ =\active\let =\ttxobeysp}}
  18. \def\ttxobeysp{{\cmtt\@xobeysp}}  % use the computer modern \tt space.
  19.  
  20. % \etobeytabs turns all tabs into 8 non-breakable spaces.
  21. {\catcode`\^^I=\active\gdef\etobeytabs{\catcode`\^^I=\active\let^^I=\xetobeytabs}}
  22. \def\xetobeytabs{\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp\@xobeysp}
  23.  
  24. % \etobeylines turns all cr's into non-breakable \par's.
  25. {\catcode`\^^M=\active\gdef\etobeylines{\catcode`\^^M=\active\let^^M=\xetobeylines}}
  26. \def\xetobeylines{\par\penalty10000}
  27.  
  28. % \obeycrsp turns cr's into non-breakable spaces
  29. {\catcode`\^^M=\active\gdef\obeycrsp{\catcode`\^^M=\active\let^^M=\@xobeysp}}
  30.  
  31. % \specialsemi makes ';text<cr>' behave like '{\tt text}<cr>'.
  32. {\catcode`;=\active\gdef\specialsemi{\catcode`;=\active\let;=\xspecialsemi}}
  33. {\catcode`\^^M=\active\gdef\xspecialsemi#1^^M{{\cmtt #1}^^M}}
  34.  
  35. % \specialquote makes '"text"' behave like '\verb| text |'.
  36. {\catcode`"=\active\gdef\specialquote{\catcode`"=\active\let"=\xspecialquote}}
  37. {\catcode`"=\active\gdef\xspecialquote#1"{{\cmtt ~#1~}}}
  38.  
  39. % Set up evaltrace environment, in which most of the common special
  40. % characters appearing in code are treated verbatim, namely:
  41. %                    _ # & ^ $ ~ @ " %
  42. %
  43. % Note: \ { } are still enabled so that macros can be called in this
  44. % environment.  Also, + is an escape character just like \.  Use \\, \+,
  45. % \{ and \} to use these characters verbatim in this environment.
  46. %
  47. % Note: this environment allows no breaking of lines whatsoever; not
  48. % at spaces or hypens.  To arrange for a break use the standard \- macro,
  49. % or the \= macro which breaks, but inserts nothing.  This is useful,
  50. % for example for allowing hypenated identifiers to be broken, e.g.
  51. % FOO-\=BAR.
  52.  
  53. \def\setupevaltrace{\parsep=0pt\parindent=0pt%
  54.   \small\et\frenchspacing%
  55.   \def\\{\char`\\}\def\+{\char`\+}%
  56.   \catcode`\#=11\catcode`\&=11\catcode`\^=11\catcode`\_=11\catcode`\>=11%
  57.   \catcode`\-=11\catcode`\.=11\catcode`\*=11\catcode`\]=11%
  58.   \catcode`\$=11\catcode`\'=11\catcode`\~=11\catcode`\@=11%
  59.   \catcode`\"=11\catcode`+=0\catcode`\%=11\catcode`\`=11\catcode`\==11%
  60.   \etobeytabs\etobeyspaces\specialsemi\specialquote}
  61.  
  62. % "Big" evaltrace environment as described above.  Blank lines are
  63. % not preserved (use \strut for this), and diagrams are not kept on
  64. % one page.  Diagrams are indented by the same amount as quotes.
  65. % Note: to increase left margin, use \leftmargini=1in.
  66.  
  67. \newenvironment{bigevaltrace}%
  68.   {\list{}{\parsep=0pt\leftmargin=0pt\labelwidth=0pt\itemindent=0pt%
  69. \listparindent=0pt}\item[]\setupevaltrace%
  70. \obeylines}%
  71.   {\endlist}
  72.  
  73. % Evaltrace is just like bigevaltrace, but everything the diagram is
  74. % kept on one page.  This works by setting a huge penalty for breaking
  75. % between lines of the diagram.
  76.  
  77. \newenvironment{evaltrace}%
  78.   {\list{}{\parsep=0pt\labelwidth=0pt\itemindent=0pt%\leftmargin=0pt
  79. \listparindent=0pt}\item[]\setupevaltrace%
  80. \etobeylines}%
  81.   {\endlist}
  82.  
  83. % Various macros for drawing joints and arrows.
  84.  
  85. % \--> and \_-> draw upper and lower thin right arrows.
  86. {\catcode`\>=11\catcode`\-=11\gdef\-->{q->}}
  87. {\catcode`\>=11\catcode`\.=11\catcode`\-=11\gdef\.->{I->}}
  88. {\catcode`\>=11\catcode`\-=11\catcode`\_=11\gdef\_->{a->}}
  89.  
  90. % \**> and \_*> draw upper and lower thick right arrows.
  91. {\catcode`\>=11\catcode`\*=11\gdef\**>{T\symbol{95}]}}
  92. {\catcode`\>=11\catcode`\_=11\gdef\__>{Q\symbol{95}]}}
  93. {\catcode`\>=11\catcode`\*=11\catcode`\_=11\gdef\_*>{A\symbol{95}]}}
  94.  
  95. % \%%> and \_%> draw upper and lower hollow right arrows.
  96. {\catcode`\>=11\catcode`\%=11\gdef\%%>{t=!}}
  97. {\catcode`\>=11\catcode`\%=11\catcode`\_=11\gdef\_%>{D=!}}
  98. {\catcode`\>=11\catcode`\==11\gdef\==>{E=!}}
  99.  
  100. % \..> and \_.> draw upper and lower dashed right arrows.
  101. {\catcode`\>=11\catcode`\.=11\gdef\..>{e.)}}
  102. {\catcode`\>=11\catcode`\.=11\catcode`\_=11\gdef\_.>{d.)}}
  103.  
  104. \makeatother
  105.